package lunchy.mvc.models;

import java.io.Console;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import lunchy.data.classes.CLunchyMenuGroup;
import lunchy.data.classes.CLunchyMenuItem;
import lunchy.data.interfaces.ILunchyMenu;
import lunchy.data.interfaces.ILunchyMenuGroup;
import lunchy.data.interfaces.ILunchyMenuItem;
import lunchy.main.CLunchyApplication;
import lunchy.mvc.views.CLunchyMenuEditGroupView;
import lunchy.mvc.views.CLunchyMenuEditItemView;

public class CLunchyMenuEditModel
{
	private ILunchyMenu menu;
	
	public CLunchyMenuEditModel()
	{
		menu = CLunchyApplication.getInstance().dataConnection.getMenuDAO().getAllMenuItems();
	}

	public ArrayList<ILunchyMenuGroup> getMenuGroups()
	{
		return menu.getMenuGroups();
	}
	
	public boolean isActiveItem(Integer id)
	{
		return menu.findMenuItemById(id).isActive();
	}
	
	public void activateItem(Integer id)
	{
		menu.findMenuItemById(id).setActive(true);
	}
	
	public void deactivateItem(Integer id)
	{
		menu.findMenuItemById(id).setActive(false);
	}
	
	public boolean saveMenu()
	{
		return CLunchyApplication.getInstance().dataConnection.getMenuDAO().saveMenu(menu);
	}
	
	public ILunchyMenu getMenu()
	{
		return menu;
	}
	
	public void addGroup()
	{
		ILunchyMenuGroup tempGroup = new CLunchyMenuGroup(0, "");

		new CLunchyMenuEditGroupView(tempGroup);

		if(tempGroup.getName() != "")
		{
			tempGroup.setId(menu.increaseMaxGroupId());
			menu.addMenuGroup(tempGroup);
		}
	}
	
	public void editGroup(Integer groupId)
	{
		new CLunchyMenuEditGroupView(menu.findMenuGroupById(groupId));
	}

	public void editItem(Integer itemId)
	{
		new CLunchyMenuEditItemView(menu.findMenuItemById(itemId));
	}

	public void addItem(Integer groupId)
	{
		ILunchyMenuItem tempItem = new CLunchyMenuItem(0, "", 0, true);

		new CLunchyMenuEditItemView(tempItem);

		if(tempItem.getName() != "")
		{
			tempItem.setId(menu.increaseMaxItemId());
			menu.findMenuGroupById(groupId).addMenuGroupItem(tempItem);
		}
	}

	public void deleteGroup(Integer groupId)
	{
		menu.deleteGroup(groupId);
	}
	
	public void deleteItem(Integer itemId)
	{
		menu.deleteItem(itemId);
	}
}
